/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.SysAdmin;

import org.springframework.validation.Validator;
import org.springframework.validation.Errors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author s4201567 Tony Yu
 */
public class EditPADetailsValidator implements Validator {
    protected final Log logger = LogFactory.getLog(getClass());
    
    public boolean supports(Class clazz) {
        return EditPADetails.class.equals(clazz);
    }
    
    public void validate(Object obj, Errors errors) {
        
        EditPADetails mpa = (EditPADetails) obj;
        String numExpiryDays = mpa.getNumExpiryDays();
        String email = mpa.getEmail();
        
        logger.info("Validating input fields.");
        
        /* Checks if the input field is not below 0 */
        if (numExpiryDays == "") {
            errors.rejectValue("numExpiryDays", "errors.not-specified", null, "This field cannot be empty");
        } else if (email == "") {
            errors.rejectValue("password", "errors.not-specified", null, "This field cannot be empty");
        } else {
            logger.info("Processing...");
        }
    }
}
